package sivan.domain;

import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by sivan on 2019/2/24.
 */
public class MyApplicationContext extends ClassPathXmlApplicationContext {

    public MyApplicationContext(String location) {
        super(location);
    }

    /**
     * 继承ClassPathXmlApplicationContext类重写postProcessBeanFactory可以在BeanDefinition加载完成之后，
     * 在beanPostProcess执行之前bean实例之前完成对bean定义的修改。
     * 由refresh()的this.postProcessBeanFactory(beanFactory)方式调用
     * @param beanFactory
     */
    @Override
    protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
        System.out.println("执行了MyApplicationContext的postProcessBeanFactory方法");
        BeanDefinition beanDefinition = beanFactory.getBeanDefinition("person");
        PropertyValue propertyValue=new PropertyValue("userName", "海上捞盐");
        beanDefinition.getPropertyValues().addPropertyValue(propertyValue);
    }
}
